{include file="../app/common/admin/lib/header.html"  title="分类展示"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">图文分类管理<span>在这里对图文分类进行管理</span></h2>
  <a href="javascript:void(0);" class="btn btn-success btn-sm right js_addCategory"><i class="icon-add"></i>添加分类</a>
  <a href="{AnUrl('appmsg/admin')}" class="btn btn-default btn-sm right" style="margin-right:10px;">&lt;&nbsp;返回图文列表</a>
</div>
<div class="search-level1 clearfix">
  <form action="category/admin" method="get" class="js_searchForm">
    <input type="text" class="left js_title" name="search_filter[title]" value="{$search_filter.title}">
    <button type="submit" class="btn btn-success btn-sm left js_searchBtn">搜索</button>
    <a href="javascript:void(0);" class="close js_advanced">高级搜索<em></em></a>
  </form>
</div>
<div class="search-form js_advancedForm" {if $is_advenced == 0}style="display:none;"{/if}>
  <form action="category/admin" method="get" class="js_categorySearchForm">
    <p>
      <label for="" class="search-f-label">分类标题：</label>
      <input type="text" class="search-f-ipt1 js_title" name="search_filter[title]" value="{$search_filter.title}">
    </p>
    <p>
    <label for="" class="search-f-label">添加时间：</label>
      <input type="text" class="search-f-ipt1 search-f-ipt2 js_startDate" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
      <span class="search-f-line"></span>
      <input type="text" class="search-f-ipt1 search-f-ipt2 js_stopDate" name="search_filter[_date]" value="{$search_filter.stop_date}" id="stopDate">
    </p>
    <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_advencedSearchBtn">搜索</button></p>
  </form>
</div>
<!--start:列表-->
<div class="js_categoryListBox"><img class="js_loadingImg" style="display:block;margin:0 auto;width:220px;" src="{$smarty.const.SITE_URL}/images/loading2.gif"></div>
<img class="js_loadingImg" style="display:none;margin:0 auto;width:220px;" src="{$smarty.const.SITE_URL}/images/loading2.gif">
<!--end:列表-->
<script>
var resName = 'category';
var status  = 1;
$('.js_categoryListBox').load(siteUrl+'/category/admin/load_list?res_name=appmsg&status='+status);
$(function(){
  // 添加分类
  $('.js_addCategory').live('click', function(){
    var thisObj   = $(this);
    var title     = thisObj.attr('data-title');
    var id        = thisObj.attr('data-id');
    var type      = thisObj.attr('data-type');
    var viewOrder = thisObj.attr('data-view-order');
    var content   = $('<div style="width: 300px;padding-top: 30px;">\
                         <div><span style="margin-bottom:10px;margin-left: 30px;display: inline-block;width: 60px;">标题:</span><input style="width:150px;" class="js_title set-menu-ipt1 " type="text" value=""></div>\
                         <div><span style="margin-left: 30px;display: inline-block;width: 60px;">排序:</span><input style="width:150px;" class="js_viewOrder set-menu-ipt1 " type="text" value=""></div>\
                       </div>');
    var DD = ace.dialog({
      'title':'添加分类',
      'content':content,
      'init':function(){
        content.closest('.aceDialog').css('width', '300px');
        content.closest('.aceDialog').find('.okBtn').css('margin-left', '30px');
        if (type == 'edit') {
          content.find('.js_title').val(title);
          content.find('.js_viewOrder').val(viewOrder);
        }
      },
      'ok':function(){
        var newTitle     = $.trim(content.find('.js_title').val());
        var newViewOrder = $.trim(content.find('.js_viewOrder').val());
        var postData     = {
            'id'         : id,
            'title'      : newTitle,
            'res_name'   : 'appmsg',
            'view_order' : newViewOrder
        };
        if (getFontNum(newTitle) > 10) {
          showMsg('分类标题不能超过10个字');
          return;
        }
        $.post(siteUrl+'/category/admin/ajax_save', postData, function(json){
          if (json.info != 'ok') {
            showMsg(json.info);
            return;
          }
          
          $('.js_categoryListBox').load(siteUrl+'/category/admin/load_list?res_name=appmsg&status='+status);
          DD.close();
        }, 'json');
      }
    });
  });
  
  // 搜索
  $('.js_advencedSearchBtn').click(function(e){
    e.preventDefault();
    var loadImg = $('.js_loadingImg').clone();
    $('.js_categoryListBox').html(loadImg).find('.js_loadingImg').show();
    $('.js_searchForm')[0].reset();
    var thisForm  = $(this).closest('form');
    var title     = $.trim(thisForm.find('.js_title').val());
    var startDate = $.trim(thisForm.find('.js_startDate').val());
    var stopDate  = $.trim(thisForm.find('.js_stopDate').val());
    if (startDate > stopDate) {
      showMsg('结束时间必须大于开始时间');
      return false;
    }
    $('.js_categoryListBox').load(siteUrl+'/category/admin/load_list?res_name=appmsg&status='+status+'&title='+title+'&start_date='+startDate+'&stop_date='+stopDate,function(){
      $('.js_loadingImg').hide();
    });
  });
  $('.js_searchBtn').click(function(e){
    e.preventDefault();
    var loadImg = $('.js_loadingImg').clone();
    $('.js_categoryListBox').html(loadImg).find('.js_loadingImg').show();
    $('.js_categorySearchForm')[0].reset();
    var thisForm  = $(this).closest('form');
    var title     = $.trim(thisForm.find('.js_title').val());

    $('.js_categoryListBox').load(siteUrl+'/category/admin/load_list?res_name=appmsg&status='+status+'&title='+title,function(){
      $('.js_loadingImg').hide();
    });
  });
  
  // status
  $('.js_categoryListBox').on('click', '.js_status', function(e){
    status = $(this).attr('data-status');
    $('.js_searchForm')[0].reset();
    $('.js_categorySearchForm')[0].reset();
    $('.js_categoryListBox').load(siteUrl+'/category/admin/load_list?res_name=appmsg&status='+status);
  });
  
  // 高级搜索
  $('.js_advanced').click(function(e){
    e.preventDefault();
    var thisObj = $(this);
    var outBox  = thisObj.closest('form');
    if (thisObj.hasClass('js_isOpen')) {
      thisObj.removeClass('js_isOpen open');
      outBox.find('input').show();
      outBox.find('button').show();
      $('.js_advancedForm').hide();
    } else {
      thisObj.addClass('js_isOpen open');
      outBox.find('input').hide();
      outBox.find('button').hide();
      $('.js_advancedForm').show();
    }
  });
  
  // ajax分页 点击load对应内容
  $('.js_categoryListBox').on('click', '.js_pageContent a', function(e){
    e.preventDefault();
    var urlStart = /^http:/;
    var url = '';
    if (!urlStart.test($(this).attr('href'))) {
      url += siteUrl + '/' ;
    }
    
    url += $(this).attr('href');
    
    $('.js_categoryListBox').load(url);
  });
});
</script>
{include file="../app/common/admin/lib/footer.html"}